package com.pets.springboot_petshop.controller;

import com.pets.springboot_petshop.entity.Order;
import com.pets.springboot_petshop.entity.Petknowledge;
import com.pets.springboot_petshop.pojo.Result;
import com.pets.springboot_petshop.service.PetknowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 下午5:00 周二
 * @Description: 宣传栏控制器
 */
@RestController
@RequestMapping("/Petknowledge")
public class PetknowledgeController {
    @Autowired
    private PetknowledgeService petknowledgeService;
    //id查询
    @GetMapping("select")
    private Result select(@RequestParam int id) {
        Petknowledge petknowledge = petknowledgeService.select(id);
        if (petknowledge != null) {
            return Result.success(petknowledge);
        }else {
            return Result.error("获取失败");
        }
    }
    //user_id查询
    @GetMapping("selectadmin_id")
    private Result selectadmin_id(@RequestParam int admin_id) {
        List<Petknowledge> petknowledge = petknowledgeService.selectadmin_id(admin_id);
        if (petknowledge != null) {
            return Result.success(petknowledge);
        }else {
            return Result.error("获取失败");
        }
    }
    //查询所有
    @GetMapping("/findAll")
    private Result findAll() {
        List<Petknowledge> petknowledge = petknowledgeService.findAll();
        if(petknowledge == null || petknowledge.isEmpty()){
            return Result.error("获取失败");
        }else {
            return Result.success(petknowledge);
        }
    }
    //添加
    @PostMapping("add")
    private Result add(@RequestBody Petknowledge petknowledge) {
        if (petknowledgeService.add(petknowledge)>0){
            return Result.success("新增成功");
        }else {
            return Result.error("获取失败");
        }
    }

    //删除
    @PostMapping("delete")
    private Result delete(@RequestParam Integer id){
        if (petknowledgeService.delete(id)>0){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    //修改数据
    @PostMapping("update")
    private Result update(@RequestBody Petknowledge petknowledge){
        if (petknowledgeService.update(petknowledge)>0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }
}
